{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<tf.Variable 'v1:0' shape=(1, 2) dtype=float32_ref>\n",
      "V1: [[-1.0590589  -0.97511166]]\n",
      "V2: [[ 1.6811557  -0.7648995   0.28499973]\n",
      " [-0.19369818 -0.38322988  0.8375284 ]]\n",
      "V1: [[-1.0590589  -0.97511166]]\n",
      "V2: [[ 1.6811557  -0.7648995   0.28499973]\n",
      " [-0.19369818 -0.38322988  0.8375284 ]]\n",
      "Model saved in file:  save/model.ckpt\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "tf.reset_default_graph()  \n",
    "v1 = tf.Variable(tf.random_normal([1,2]), name=\"v1\")\n",
    "v2 = tf.Variable(tf.random_normal([2,3]), name=\"v2\")\n",
    "print(v1)\n",
    "init_op = tf.global_variables_initializer()\n",
    "saver = tf.train.Saver()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init_op)\n",
    "    print (\"V1:\",sess.run(v1))  \n",
    "    print (\"V2:\",sess.run(v2))\n",
    "    saver_path = saver.save(sess, \"save/model.ckpt\")\n",
    "    print (\"V1:\",sess.run(v1))  \n",
    "    print (\"V2:\",sess.run(v2))\n",
    "    print (\"Model saved in file: \", saver_path) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Restoring parameters from save/model.ckpt\n",
      "V1: [[-1.0590589  -0.97511166]]\n",
      "Model restored\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "# v1 = tf.Variable(tf.random_normal([1,2]), name=\"v1\")\n",
    "# v2 = tf.Variable(tf.random_normal([2,3]), name=\"v2\")\n",
    "saver = tf.train.Saver()\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    saver = tf.train.import_meta_graph('./save/model.ckpt.meta')\n",
    "    saver.restore(sess, 'save/model.ckpt')\n",
    "    print (\"V1:\",sess.run('v1:0'))  \n",
    "#     print (\"V2:\",sess.run(v2))\n",
    "    print (\"Model restored\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Restoring parameters from ./save\\model.ckpt\n",
      "[[-1.0590589  -0.97511166]]\n"
     ]
    }
   ],
   "source": [
    "# import tensorflow as tf\n",
    "# tf.reset_default_graph()\n",
    "with tf.Session() as sess:    \n",
    "    saver = tf.train.import_meta_graph('./save/model.ckpt.meta')\n",
    "    saver.restore(sess,tf.train.latest_checkpoint('./save'))\n",
    "#     saver.restore(sess, 'save/model.ckpt')\n",
    "    print(sess.run('v1:0'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
